from rest_framework import serializers

from areas.models import Area


class AreaSerializer(serializers.ModelSerializer):
    """行政区域信息序列化器"""
    # 如果此时是查询 所有的省,所有的省数据就用此序列化器
    class Meta:
        model = Area
        fields = ['id', 'name']


class SubsAreaSerializer(serializers.ModelSerializer):
    """子行政区域信息序列化器"""
    # 如果是查询单个省 或单个市时,就用此序列化器

    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
